package vrp;

import java.util.Comparator;

public class Array2DComparator implements Comparator {
    private int columnToSortOn;
    private int direction; //1 for ascending, -1 for descending
    
    Array2DComparator(int columnToSortOn, int direction) {
      this.columnToSortOn = columnToSortOn;
      this.direction = direction;
    }

    public int compare(Object o1, Object o2) {
    	double[] row1 = (double[])o1;
    	double[] row2 = (double[])o2;
    	
    	int result = 0;

        if (row1[columnToSortOn]<(row2[columnToSortOn])) {
        	result = -1;
        }
        if (row1[columnToSortOn]>(row2[columnToSortOn])) {
        	result = 1;
        }
        
        return result*this.direction;
    }
}